package cn.rengy.web.framework.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.rengy.lang.ResultEntity;
/**
 * 统一访问入口
 * @author rengy
 *
 */
@Controller
public class PortalController {
	
	@Autowired
	private PortalService portalService;
	
	@RequestMapping(value="/access/get",method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity<?> get(HttpServletResponse response,HttpServletRequest request,@RequestParam("action") String action){
		return portalService.portal(request,response,action,null);
	}
	
	@RequestMapping(value="/access/postFile",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<?> postFile(HttpServletResponse response,HttpServletRequest request,@RequestParam("action") String action){
		return portalService.portal(request,response,action,null);
	}
	
	@RequestMapping(value="/access/post",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<?> post(HttpServletResponse response,HttpServletRequest request,@RequestParam("action") String action,@RequestBody(required=false) Map<String,Object> paramMap){
		return portalService.portal(request,response,action,paramMap);
	}
	
	@RequestMapping(value="/authenticated/access/post",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<?> securityPost(HttpServletResponse response,HttpServletRequest request,@RequestParam("action") String action,@RequestBody(required=false) Map<String,Object> paramMap){
		return portalService.portal(request,response,action,paramMap);
	}
	
	@RequestMapping(value="/access/download",method = {RequestMethod.GET})
    public void download(HttpServletResponse response,@RequestParam("action") String action,HttpServletRequest request) throws Exception{
		portalService.portal(request,response,action,null);
    }
}
